package com.emmmya.ocs.modules.system.serviceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.emmmya.ocs.common.base.BaseDao;
import com.emmmya.ocs.common.entity.IntermediateEntity;
import com.emmmya.ocs.modules.system.dao.RoleDao;
import com.emmmya.ocs.modules.system.dao.mapper.RoleMapper;
import com.emmmya.ocs.modules.system.entity.Role;
import com.emmmya.ocs.modules.system.service.RoleService;
import com.emmmya.ocs.modules.system.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private RoleDao roleDao;

    @Override
    public BaseDao<Role, Long> getRepository() {
        return roleDao;
    }

    @Override
    public List<Role> findRolesByDefaultRole(boolean defaultRole){
        return roleDao.findRolesByDefaultRole(defaultRole);
    }


    @Override
    public IPage<Role> getListByPage(RoleVo vo) {
        IPage<Role> page = vo.createPage();
        roleMapper.selectPage(page, vo.createWrapper());
        return page;
    }

    @Override
    public int deleteRoleMenuByRoleId(Long id){
       return  roleMapper.deleteRoleMenuByRoleId(id);
    }

    @Override
    public int insertRoleMenus(List<IntermediateEntity> roleMenus){
        return  roleMapper.insertRoleMenus(roleMenus);
    }

    @Override
    public int deleteRolePermissionByRoleId(Long id) {
        return roleMapper.deleteRolePermissionByRoleId(id);
    }

    @Override
    public int insertRolePermissions(List<IntermediateEntity> roleMenus) {
        return roleMapper.insertRolePermissions(roleMenus);
    }


}
